/*
 * Arm SCP/MCP Software
 * Copyright (c) 2018-2021, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef INTERNAL_THERMAL_SENSOR_H
#define INTERNAL_THERMAL_SENSOR_H

#define THERMAL_BASE_ADDRESS 0x48190000
#define THERMAL_INDIVIDUAL_BASE_OFFSET 0x800
#define THERMAL_INDIVIDUAL_SENSOR_OFFSET 0x80

/* base address of the thermal sensor */
#define THERMAL_SENSOR0_BASE_ADDRESS_OFFSET 0x800
#define THERMAL_SENSOR1_BASE_ADDRESS_OFFSET 0x880
#define THERMAL_SENSOR2_BASE_ADDRESS_OFFSET 0x900
#define THERMAL_SENSOR3_BASE_ADDRESS_OFFSET 0x980
#define THERMAL_SENSOR4_BASE_ADDRESS_OFFSET 0xA00
#define THERMAL_SENSOR5_BASE_ADDRESS_OFFSET 0xA80
#define THERMAL_SENSOR6_BASE_ADDRESS_OFFSET 0xB00
#define THERMAL_SENSOR7_BASE_ADDRESS_OFFSET 0xB80
#define THERMAL_SENSOR8_BASE_ADDRESS_OFFSET 0xC00
#define THERMAL_SENSOR9_BASE_ADDRESS_OFFSET 0xC80
#define THERMAL_SENSOR10_BASE_ADDRESS_OFFSET 0xD00
#define THERMAL_SENSOR11_BASE_ADDRESS_OFFSET 0xD80
#define THERMAL_SENSOR12_BASE_ADDRESS_OFFSET 0xE00
#define THERMAL_SENSOR13_BASE_ADDRESS_OFFSET 0xE80
#define THERMAL_SENSOR14_BASE_ADDRESS_OFFSET 0xF00
#define THERMAL_SENSOR15_BASE_ADDRESS_OFFSET 0xF80

/* register offset */
#define THERMAL_MACROINFO_G_OFFSET 0x000
#define THERMAL_ALLCONFIG_OFFSET 0x00C

#define THERMAL_TS_RESET_OFFSET 0x010
#define THERMAL_TS_EN_OFFSET 0x014
#define THERMAL_TS_CT_OFFSET 0x018
#define THERMAL_TS_ADJ_OFFSET 0x01C

#define THERMAL_IRQOUT_OFFSET 0x020
#define THERMAL_IRQCLR_OFFSET 0x024
#define THERMAL_IRQMASK_OFFSET 0x028
#define THERMAL_IRQSTATUS_OFFSET 0x02C

#define THERMAL_TSDATA_VALID_X_OFFSET 0x030
#define THERMAL_TSDATA_X_OFFSET 0x034

#define THERMAL_HI_FULL_TEMP_OFFSET 0x040
#define THERMAL_HI_NEAR_TEMP_OFFSET 0x044
#define THERMAL_LO_NEAR_TEMP_OFFSET 0x048
#define THERMAL_LO_FULL_TEMP_OFFSET 0x04C

#define THERMAL_HYS_TEMP_OFFSET 0x050

#define THERMAL_ENABLE 0x1
#define THERMAL_DISABLE 0x0

#define THERMAL_SUCCESS 0x0
#define THERMAL_FAIL 0x1

#define THERMAL_SENSOR_BASE(a)                               \
    (THERMAL_BASE_ADDRESS + THERMAL_INDIVIDUAL_BASE_OFFSET + \
     (a * (THERMAL_INDIVIDUAL_SENSOR_OFFSET)))

int thermal_enable(void);

#endif /* INTERNAL_THERMAL_SENSOR_H */
